from pybrain.rl.environments import Task
from scipy import array

from actions import Actions

class BlackRLTask(Task):

    def getReward(self):
        # Compute and return the current reward
        player = self.env.perseus[0]
        dealer = self.env.perseus[1]

        if sum(player) > 21:
            self.env.reset()
            reward = -1.
        else:
            reward = 1.

        return reward

    def performAction(self, action):
        # Pass the action to the super class,
        # we don't care here what the action is
        print "Performing Action: " +  str(int(action[0]))
        Task.performAction(self, int(action[0]))

    def getObservation(self):
        # Return a unique value for the current state we are in
        obs = array([sum(self.env.perseus[0])])
        return obs
